<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>">

<title>学生资料</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<%@include file="/pages/head/head.jsp"%>
<style type="text/css">
.tdcenter{
text-align: center;
vertical-align: middle;
}
</style>
</head>
<body>
	<div id="wrapper">
		<!-- 左边菜单 -->
		<%@include file="/pages/left/leftmenu.jsp"%>

		<div id="page-wrapper" class="gray-bg dashbard-1">
			<!-- 引入top菜单 -->
			<%@include file="/pages/left/topmenu.jsp"%>

			<!--左边内容开发，开始  -->
			<div class="row wrapper border-bottom white-bg page-heading">
				<div class="col-lg-10">
					<h2>学生资料</h2>
					<ol class="breadcrumb">
						<li><a href="index.html">主页</a></li>
						<li><a>学生资料</a></li>
						<li><strong>添加学生资料</strong></li>
					</ol>
				</div>
				<div class="col-lg-2"></div>
			</div>
			<div class="wrapper wrapper-content animated fadeInRight">

				<div class="row">
					<div class="col-lg-14">
						<div class="ibox float-e-margins">
							<div class="ibox-title">
								<h5>添加学生资料</h5>
								<div class="ibox-tools">
									<a class="collapse-link"> <i class="fa fa-chevron-up"></i>
									</a>
								</div>
							</div>
							<div class="ibox-content">
							 <div class="table table-bordered ">
								<table width="100%" class="tabStyle table table-bordered" style="margin-bottom: 0;  ">
								<tr >
								<td style="text-align: center;vertical-align: middle;" width="8%">搜索条件</td>
								<td style="text-align: center;vertical-align: middle;" width="8%">学号</td>
								<td><input class="form-control" id="stuno" name="stuno"> </td>
								<td style="text-align: center;vertical-align: middle;" width="5%">姓名</td>
								<td><input class="form-control" id="stuname" name="stuname" > </td>
								
								<td style="text-align: center;vertical-align: middle;" width="5%">班级</td>
								<td>
 									<select class="form-control m-b" name="classId" id="classId">
                                    <option value="0">--请选择--</option>
                                     <c:forEach items="${requestScope.classAll }" var="eachClass">  
                            		<option value="${eachClass.classId }">${eachClass.classCode } - ${eachClass.className }</option>
                                     </c:forEach>  
                                    </select>
								 </td>
								<td> <button class="btn btn-primary"  type="button" onclick="queryclass()">查询</button></td>
								</tr>
								
								</table>
                               </div> 
                            
								<div class="table table-bordered">
								<table id="tabelid" width="100%" class="tabStyle tabStyle1 table table-bordered" style="margin-bottom: 0">
									<tr>
										<th width="4%">序号</th>
										<th width="14%">学号</th>
										<th width="18%">姓名</th>
										<th width="28%">班级</th>
										<th width="8%">性别</th>
										<th width="10%">操作</th>
									</tr>

								</table>
								<div style="float: left;">
									共<strong id="total"></strong>条记录
								</div>
								<div id="pager" style="float: right;"></div>
							</div>
							</div>
							

						</div>
					</div>
				</div>
<input type="hidden" id="__page" name="page" value="1"/>

			</div>
		
		</div>
	</div>
	<%@include file="/pages/head/foot.jsp"%>

	<script>

	  var pageCurrent = 1;
	
	$(function(){
		//date
        $('.input-group.date').datepicker({
            todayBtn: "linked",
            keyboardNavigation: false,
            forceParse: false,
            calendarWeeks: true,
            autoclose: true
        });
	});
		function PageClick(pageclickednumber) {
			pageCurrent = pageclickednumber;
			
			$("#__page").val(pageclickednumber);
			
			
			var url = "${pageContext.request.contextPath}/student/queryStudents.do";
			 var param = {"page" : pageclickednumber,"stuno":$("#stuno").val(),"stuname":$("#stuname").val(),"classId":$("#classId").val()}; 
			$.post(url,param,function(data) {
								$('.tabStyle1 tr:not(:first)').remove();
								for ( var i in data) {
									pageCount = data[i].pageCount;
									if (pageCount > 0) {
										$("#total").text(data[i].total);
										$("#pager").pager({pagenumber : pageclickednumber,pagecount : pageCount,buttonClickCallback : PageClick
										});
										var datas = data[i].rows;
										for ( var j in datas) {
											if (j == "remove") {
												return;
											}
											var tr = $("<tr></tr>");
											var jj = parseInt(j) + 1;
											var mindex = (jj < 10 ? "0" + (jj): jj);
											$("<td></td>").append(mindex).appendTo($(tr));
											$("<td></td>").append(datas[j].stuno).appendTo($(tr));
											$("<td></td>").append(datas[j].stuname).appendTo($(tr));
											$("<td></td>").append(datas[j].classname).appendTo($(tr));
											$("<td></td>").append(datas[j].sex).appendTo($(tr));
											 var no_id = datas[j].stuId;
											var html = "<a href='${pageContext.request.contextPath}/student/toUpdateStudents.do?stuId="+ no_id+"'>编辑</a>｜<a href='${pageContext.request.contextPath}/student/deleteStudents.do?stuId="+ no_id+ "&pageCounts= "+pageclickednumber
													+"' onclick=\"return deleteModel();\">删除</a>";
        								
											$("<td></td>").append(html).appendTo($(tr)); 
											$(tr).appendTo($("#tabelid"));
											$("#tabelid tr:odd").addClass("bgWhite");
										}
									} else if (typeof (data[i].rows) == 'undefined') {
										window.location.reload();
									}
									var len = data[i].rows.length;

									if (len == 0) {
										$("#total").text(0);
										$("#pager").pager({
											pagenumber : pageclickednumber,
											pagecount : 0,
											buttonClickCallback : PageClick
										});
									}
								}
								if (typeof data.page == 'undefined') {
									for (var k = 0; k < 10; k++) {
										var tr = $("<tr></tr>");
										$("<td colspan='9'>&nbsp;</td>")
												.appendTo($(tr));
										$(tr).appendTo($("#tabelid"));
										$("#tabelid tr:odd")
												.addClass("bgWhite");
										$("#total").text(0);
										$("#pager").pager({
											pagenumber : pageclickednumber,
											pagecount : 0,
											buttonClickCallback : PageClick
										});
									}
								}

							});
		};

		var pageCount = 0;
		$(function() {

			if (pageCount == 0) {
				//页面加载时判断加载的页数
				if("${requestScope.flag }" == "succ"){
					PageClick(${requestScope.pageCounts });
					return;
				}
				
				PageClick(1);
			}
			//--------------------------
			//应用按钮
			//--------------------------

			$('.btn').click(function() {

				PageClick(1);
			});

		});
		
		function deleteModel(){
			if(confirm('您确定删除吗？')) {
				return true;
			}else{
				return false;
			}
		}
		
		function queryclass(){
			PageClick(1);
		}
		

		
	</script>
</body>
</html>